<?php
	header('content-type:text/html;charset=utf-8'); 
	//重要!兩種情況中都要判斷DID是否存在,DID不存在,還要判斷工單號和機台號是否為空
	//2018-3-16 11:08:32注釋:想起來好像前端就應該做判斷過濾掉這種情況
	//$GX=$_GET["nos"];
	
	$DQJT = $_POST["DQJT"];//当前机台
	
	
	$pdo =new pdo("mysql:host=127.0.0.1;port=3306;dbname=tddb;","root","tdled2018");
	$pdo->query("set character set 'utf8'");//读库 
	$pdo->query("set names 'utf8'");//写库 
	
	$sql = 
	"SELECT  COUNT(*) AS NUMBER,`DQJT` ,`name`,`order_id` ,`except_pho`,`startime`
		FROM  `fix` 
		
		WHERE  `DQJT` =  '".$DQJT."'
		
		AND  `endtime` IS NULL 
		"
	;
	/* $sql = 
	"SELECT 
		 A.ChuLiCode AS 处理代码
		,B.YiChangXianXiang AS 异常现象
		,FangFa AS 处理方法
	FROM
		yc8chulicode AS A
	LEFT JOIN
		eexcode AS B
	ON
		A.YiChangCode = B.YiChangDaiMa
	LEFT JOIN
		chulicode AS C
	ON
		A.ChuLiCode = C.ChuLiCode
	WHERE
		A.YiChangCode in
	
	
		(SELECT  COUNT(*) AS NUMBER,`DQJT` ,`name`,`order_id` ,`except_pho`,`startime`,`except_number`
		FROM  `fix` 
		
		WHERE  `DQJT` =  '".$DQJT."'
		
		AND  `endtime` IS NULL )
		"
	; */
	$res=$pdo->prepare($sql);//准备查询语句 
	$res->execute(); //执行一条查询语句
	
		
	//Fetch into associative array
	while ( $row = $res->fetch())  {
		//echo json_encode($row)."</br>";
		$dbdata[]=$row;
	}
	//Print array in JSON format
	if($dbdata[0]['NUMBER']>0){
		echo json_encode($dbdata);
	}
	else{
		echo json_encode("当前机台无异常");
	}
		//echo json_encode($rest);
	//}
	
?>